jQuery(document).ready(function(){
    //获取采购类型fieldid
    var cglxFieldId = WfForm.convertFieldNameToId("cglx");
    WfForm.bindFieldChangeEvent(cglxFieldId,function(){
        //获取这个fieldid的值
        var cglx = WfForm.getFieldValue(cglxFieldId);
        //判断采购类型是否为加急（1）
        if (1 == cglx) {
            //根据字段名称获取申请人fieldid
            var sqrFieldId = WfForm.convertFieldNameToId("sqr");
            //获取申请人的值
            var sqr = WfForm.getFieldValue(sqrFieldId);
            //获取workflowid的值
            var workflowid = jQuery("#workflowid").val();

            //申请时间fieldid
            var sqsjFieldId = WfForm.convertFieldNameToId("sqsj");
            //申请时间的值
            var sqsjVal=WfForm.getFieldValue(sqsjFieldId);
            //发起工厂
            var fqgcField=WfForm.convertFieldNameToId("fqgc");
            var  fqgcVal=WfForm.getFieldValue(fqgcField);


            //ajax传值并根据返回值给表单字段赋值
            jQuery.ajax({
                url: "/weavernorth/jsp/purchase.jsp",
                type: "post",
                data: {
                    "sqr": sqr,
                    "workflowid": workflowid,
                    "sqsj":sqsjVal,
                    "fqgc":fqgcVal
                },
                dataType: 'json',
                //异步
                async: false,
                success: function (data) {
                    //获取要赋值的字段的fieldid
                    var jjgsFieldId = WfForm.convertFieldNameToId("jjgs");
                    var jjzgsFieldId = WfForm.convertFieldNameToId("jjzgs");
                    //赋值
                    WfForm.changeFieldValue(jjgsFieldId, {value: data.num});
                    WfForm.changeFieldValue(jjzgsFieldId, {value: data.nums});

                },
                error: function (data) {  //请求失败时被调用的函数
                    alert("加载失败，请联系管理员！")
                }
            })

        }
    })
})

